<tagLib name="html" />
<include file="Public:header" />
<script type="text/javascript" src="../Public/js/Jquery/ui/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../Public/js/artDialog/artDialog.js"></script>
<script type="text/javascript" src="../Public/js/common.js"></script>
<script type="text/javascript">
function saveTicket(id){	//保存某个小时的票池
	//获取对应id时段的票池设置
	var ticket = $("#txtTicket"+id).val();
	
	//有效性检查
	if(trim(ticket) == ""){
		alert("票池数量不能为空");
		$("#txtTicket"+id).focus();
		return false;
	}
	
	if(!IsPureInt(ticket)){
		alert("票池数量只能为整数");
		$("#txtTicket"+id).focus();
		return false;
	}
		
	//弹出提示框确认是否修改
	art.dialog({title:'设置确认', 
				content:'是否确认修改设置？', 
				lock:true,
				width:"150px",
				height:"60px",
				resize:false,
				drag:false
				},
				function()
				{
					//使用Ajax Get方法调用Action中的方法进行票池更新
					$.get("__URL__/saveTicket/id/"+id+"/ticket/"+ticket,null,function(msg){  
			            alert(msg);
			    	});
				}, 
				function(){ return; }); 
}

function endInit(){	//对于结束时间下拉框进行初始化
	//获取开始时间
	var startHour = $("#startHour").val();
	
	
	if(startHour != -1){
		//如果已经选择某一个开始时间，则根据该开始时间生成所有可以选择的结束时间
		
		//删除所有选项后首先增加默认选项
		document.getElementById("endHour").options.length = 0;
		document.getElementById("endHour").options.add(new Option("请选择结束时间", -1));
		//循环插入结束时间
		for(var i=parseInt(startHour)+1; i<=24; i++){
			document.getElementById("endHour").options.add(new Option(i+"点", i));
		}
	}
}

function checkStartInit(){	//校验开始时间是否已经选择
	var startHour = $("#startHour").val();
	if(startHour == -1){
		alert("请先选择开始时间");
	}
}

function formCheck(){	//表单检查
	//获取表单中的值
	var startHour = $("#startHour").val();
	var endHour = $("#endHour").val();
	var ticketNum = $("#ticketNum").val();

	//有效性检查
	if(startHour == -1){
		alert("请选择开始时间");
		$("#startHour").focus();
		return false;
	}
	if(endHour == -1){
		alert("请选择结束时间");
		$("#endHour").focus();
		return false;
	}
	if((ticketNum == "请输入整数") || (trim(ticketNum) == "")){
		alert("请输入票池数量");
		$("#ticketNum").focus();
		return false;
	}
	
	if(!IsPureInt(ticketNum)){
		alert("票池数量只能为整数");
		$("#ticketNum").focus();
		return false;
	}

	//弹出提示框进行设置确认
	art.dialog({title:'设置确认', 
		content:'是否确认修改票池设置？', 
		lock:true}, 
		function()
		{
			//使用Ajax Post方式提交表单内容，并根据返回结果进行列表对应更新
			$.post("__URL__/batchSaveTicket",$("#form1").serialize(),function(msg){
				alert(msg);
	            for(var i=startHour; i<endHour; i++){
	            	document.getElementById("txtTicket"+i).value = ticketNum;
	            }
	    	});
		}, 
		function(){ return; }); 
	
	return true;
}
</script>

<div class="con_box right">
  <div class="u_content">
    <div class="con_tit"> 
      <ul class="left"><img src="../Public/images/jiao.gif"/></ul>
      <ul class="tit_bg">新增票池设置</ul> 
    </div>
    <div class="con_main left">          
            <div class="left con_admin">
            <div class=" state left">                
             <div class="state_form" >
                 <form name="form1" id="form1" method="post" action="__URL__/batchSaveTicket" onsubmit="return formCheck();">             
                 <p><label>时间：</label><select id="startHour" name="startHour" class="input3" onchange="javascript:endInit()">
                 <option value=-1 selected>请选择开始时间</option>
                 	<option value=0>0点</option>
		        	<option value=1>1点</option>
		        	<option value=2>2点</option>
		        	<option value=3>3点</option>
		        	<option value=4>4点</option>
		        	<option value=5>5点</option>
		        	<option value=6>6点</option>
		        	<option value=7>7点</option>
		        	<option value=8>8点</option>
		        	<option value=9>9点</option>
		        	<option value=10>10点</option>
		        	<option value=11>11点</option>
		        	<option value=12>12点</option>
		        	<option value=13>13点</option>
		        	<option value=14>14点</option>
		        	<option value=15>15点</option>
		        	<option value=16>16点</option>
		        	<option value=17>17点</option>
		        	<option value=18>18点</option>
		        	<option value=19>19点</option>
		        	<option value=20>20点</option>
		        	<option value=21>21点</option>
		        	<option value=22>22点</option>
		        	<option value=23>23点</option>
                 </select></p>
                 <p><label>到：</label><select id="endHour" name="endHour" class="input3" onclick="javascript:checkStartInit()">
                 <option value=-1>请选择结束时间</option>
                 </select></p> 
                 <p><label>票池数量：</label><input id="ticketNum" name="ticketNum" type="text" class="input1" value="请输入整数" onfocus="javascript:if(this.value=='请输入整数') this.value=''" onblur="javascript:if(this.value=='') this.value='请输入整数'"/></p>
                 <p><input class="get"  type="button"  value="设置" onclick="return formCheck();"></p>
                 </form>                                                         
              </div>   
            </div>  
           </div> 
           <div class=" state left">
           <div class="state left"><span class="state_title">已保存的票池设置</span></div>
           <div class="or">
           <table class="left" style="width:49%;border-left:1px #a7a7a7 solid;border-top:1px #a7a7a7 solid;">                            
            	 <tr><th colspan="3">白天</th></tr>
                 <volist name="dayPoolList" id="dayPoolList" empty="暂无相关信息！">
	                 <tr>
	                    <td width="90px">{$dayPoolList.time_range}</td> 
	                   	<td width="120px"><input type="text" id="txtTicket{$dayPoolList.id}" class="input2" value="{$dayPoolList.max_ticket}"/></td>
	                    <td width="60px"><input id="btnTicket{$dayPoolList.id}" type="button"  class="input2" value="设置"  onclick="saveTicket({$dayPoolList.id})"></td>
	                 </tr>  
				 </volist>                                                                     
           </table> 
           <table class="right" style="width:49%;border-left:1px #a7a7a7 solid;border-top:1px #a7a7a7 solid;">                            
            	 <tr><th colspan="3">晚上</th> </tr>
                 <volist name="nightPoolList" id="nightPoolList" empty="暂无相关信息！">
	                 <tr>
	                    <td width="90px">{$nightPoolList.time_range}</td> 
	                   	<td width="120px"><input type="text" id="txtTicket{$nightPoolList.id}"  class="input2" value="{$nightPoolList.max_ticket}"/></td>
	                    <td width="60px"><input id="btnTicket{$nightPoolList.id}" type="button" class="input2" value="设置"  onclick="saveTicket({$nightPoolList.id})"></td>
	                 </tr>  
				 </volist>                                                                    
           </table>
           </div>         
           </div>       
    </div>     
  </div>
</div>

<tagLib name="html" />
<include file="Public:foot" />